import com.itheima.utils.DateUtils;
import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class TEST {


    @Test
    public void fun01() throws Exception {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date thisWeekMonday = DateUtils.getThisWeekMonday();//本周一的日期2019-09-09
        System.out.println(simpleDateFormat.format(thisWeekMonday));

        String day = DateUtils.parseDate2String(new Date());  //当前的日期2019-09-11
        String mouth = day.substring(0, day.lastIndexOf("-")); //当前的月份2019-09


        System.out.println(day);
        System.out.println(mouth);


        //
        //Calendar calendar = Calendar.getInstance();
        //Date time = calendar.getTime();
        //SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
        //
        //String timeFormat = simpleDateFormat.format(time);
        //System.out.println(timeFormat);
        //
        //System.out.println(calendar.get(Calendar.DATE));
        //System.out.println(calendar.get(Calendar.DAY_OF_WEEK)-1);


    }

    @Test
    public void fun02() throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date data = simpleDateFormat.parse("2019-09-08");
        Calendar cal = Calendar.getInstance();
        cal.setTime(data);
        // 获得当前日期是一个星期的第几天
        int dayWeek = cal.get(Calendar.DAY_OF_WEEK);
        if (1 == dayWeek) {
            cal.add(Calendar.DAY_OF_MONTH, -1);
        }
        cal.getFirstDayOfWeek();

        // 设置一个星期的第一天，按中国的习惯一个星期的第一天是星期一
        cal.setFirstDayOfWeek(Calendar.MONDAY);

        cal.getFirstDayOfWeek();

        // 获得当前日期是一个星期的第几天
        int day = cal.get(Calendar.DAY_OF_WEEK);
        // 根据日历的规则，给当前日期减去星期几与一个星期第一天的差值
        cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - day);
        cal.getTime();

    }
}
